using System;
using System.Data;
using System.Xml;

namespace Umbraco.Ecommerce.BusinessLogic
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class CustomerInfo
	{
		private DataTable dt;
	
		public CustomerInfo()
		{
			dt = new DataTable("data");
			dt.Columns.Add("key");
			dt.Columns.Add("value");
		}

		public CustomerInfo(XmlDocument xml)
		{
			DataSet ds = new DataSet("customerInfo");
			XmlReader xr = new XmlNodeReader(xml.DocumentElement);
			ds.ReadXml(xr);
			dt = ds.Tables[0];
         }

		public string GetValue(string key) {
			foreach (DataRow dr in dt.Rows) {
				if (dr["key"].ToString() == key) {
					return dr["value"].ToString();
				}
			}
			return "";
		}

		public void AddData(string Key, string Value) 
		{
			DataRow dr = dt.NewRow();
			dr["key"] = Key;
			dr["value"] = Value;
			dt.Rows.Add(dr);
		}
		
		public DataTable ToDataTable() {
			return dt.Copy();
		}

		public string ToXml() {
			DataSet ds = new DataSet("customerInfo");
			ds.Tables.Add(dt.Copy());
			XmlDataDocument d = new XmlDataDocument(ds);
			return d.OuterXml.ToString();
		}
	}
}